{% extends 'base.html' %}
{% load static %}

{% block title %}
    良言|登录
{% endblock %}

{% block header_extends %}
    <link rel="stylesheet" href="{% static 'login.css' %}">
{% endblock %}

{% block content %}
<div class="container normal-container">
    <div class="row">
        <div class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-3 col-md-4 col-md-offset-4">
            {% if not user.is_authenticated %}
                <div class="panel panel-default">
                  <div class="panel-heading">
                    <h3 class="panel-title">用户登录</h3>
                  </div>
                  <div class="panel-body">
                    <form action="" method="POST" id="login_form" autocomplete="on">
                        {% csrf_token %}
                        {% for field in login_form %}
                            <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                            {{ field }}
                            <p class="text-danger">{{ field.errors.as_text }}</p>
                        {% endfor %}
                        <span class="pull-left text-danger">{{ login_form.non_field_errors }}</span>
                        <div class="clearfix"></div>
                        <a href="{% url 'retrieve_password' %}?from={{ request.get_full_path }}">忘记密码？</a>
                        <input class="btn btn-primary pull-right" type="submit" value="登录">
                    </form>
                  </div>
                </div>
            {% else %}
                <h3>{{ user.get_nickname_or_username }}已登录，正在跳转到<a href="{% url 'home' %}">首页</a>...</h3>
                <script type="text/javascript">
                    setTimeout("window.location.href = \"{%url 'home' %}\"", 2000);
                </script>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}